# Acronym                : XmpStandAlone.mak
# Product                : Rhapsody
# Version                : 2.2
#
# Requires               : Microsoft NMAKE version 1.20 or higher
#                          TriMedia Commandtool Set v 2.2 (TCS)
#
#               Copyright (C) Philips Electronics N.V. 2003
#                 CFT Centre for Manufacturing Technology
#                       Eindhoven - The Netherlands
#
#      All rights are reserved. Reproduction in whole or in part is
#          prohibited without the written consent of the author.
#
# Description:
#   This is a simple makefile that can be used for creation of a
#   Rhapsody standalone application.
#   With simple is meant that this makefile doesn't check for any source-header
#   file dependencies. Only the time-stamp dependency between the
#   source-files and the out-file to be created is checked.
#   To ensure that everything is re-compiled and linked use the option /A
#   when invoking nmake
#
#   This makefile can be used as a template for any standalone application.
#   To make an other application only the next two macros need to be changed:
#     APP_NAME
#     SOURCES ( list the sources in the required link-order)
#
#   The other sections of the makefile require (in most circumstances) no
#   changes
#
#   Building the application requires a command-line instruction like the
#   following:
#
#        nmake /A /F XmpStandAlone.mak CFG="Debug"
#
#   which will ReBuild the Debug version of APP_NAME
#
#

SOURCES         = $(C_SOURCES) $(CPP_SOURCES)
OLDLIBS			= C:\Data\IncaXetal\Lib

##############################################################################
#                          TCS required definitions
##############################################################################

#TCS = C:\TCS2.2
TCS = C:\Data\IncaXetal\TriMedia
XTC_BIN = C:\Data\IncaXetal\Xetal\bin
XTC_PARAMS = C:\Data\IncaXetal\Xetal\params.txt

#-----------------------------------------------------------------------------
# Defines required to define the TriMedia target and to select the correct
# TCS-libraries / Linking-mode
#-----------------------------------------------------------------------------
# general hardware independent definitions
TARGET       = tm1    # specifies TriMedia processor   (tm1 | tm2)
ENDIAN       = el     # specifies TriMedia endian-mode (el | eb)
HOST_WINDOWS = WinNT  # specifies TriMedia host-mode   used for FUGA / PRESTO
HOST_NONE    = nohost # specifies TriMedia host-mode   used for INCA
HOST_TMSIM   = tmsim
CORE		 = tm32
FP			 = fp32

#-----------------------------------------------------------------------------
# Defines/Flags required for selection of correct pSOS-components
#-----------------------------------------------------------------------------
# general definitions
PSOS_SYSTEM = $(TCS)\OS\pSOS\pSOSystem                 # location of the files

# definitions for pSOS multiprocessor
PSOS_MULTIPROC_DEFS  = -DSC_PSOS=NO -DSC_PSOSM=YES -DSC_PNA=NO -DPSOS
PSOS_MULTIPROC_LIBS  = $(PSOS_SYSTEM)\sys\os\psosm_tm_$(ENDIAN).o

# definitions for pSOS single-processor
PSOS_SINGLEPROC_DEFS = -DSC_PSOS=YES -DSC_PSOSM=NO -DSC_PNA=NO -DPSOS -DSC_PSOS_QUERY=YES
PSOS_SINGLEPROC_LIBS = $(OLDLIBS)\psos_tm_el.o

#-----------------------------------------------------------------------------
# Defines for selection of TCS-Tools and TCS Include paths
# You normally should not need to change any of the following defines
#-----------------------------------------------------------------------------
TMCC        = $(TCS)\bin\tmcc
TMLD        = $(TCS)\bin\tmld
TMAR        = $(TCS)\bin\tmar

TCS_INCLUDE = -I$(TCS)\include -I$(PSOS_SYSTEM)\include

TCS_LFLAGS_EMBEDDED_APP = \
               -btype boot \
               -mi \
               -mmio_base $(DEV_MMIO_BASE) \
               -tm_freq $(DEV_CLOCK_FREQ) \
               -load=$(DEV_APP_BASEADDRESS),$(DEV_MEM_SIZE) \
               -exec \
               -chain ___custom_boot \
               -chain ___custom_driver \
               -chain ___custom_start \
               -chain ___CC_Init_List \
               -chain ___dataprop_list \
               -chain ___component_list \
               $(OLDLIBS)\reset.o \
               $(OLDLIBS)\boot.o \
               -start=__start

TCS_LFLAGS_SIM_APP = \
               -btype boot \
               -exec \
               -chain ___custom_boot \
               -chain ___custom_driver \
               -chain ___custom_start \
               -chain ___CC_Init_List \
               -chain ___dataprop_list \
               -chain ___component_list \
               $(OLDLIBS)\reset.o \
               $(OLDLIBS)\boot.o \
               -start=__start \
               -debug


##############################################################################
#  RHAPSODY required hardware-independent definitions
##############################################################################
# Defines for specification of Rhapsody dependencies
# You normally should not need to change any of the following defines

RAP_INCLUDE = -Iinc -I$(RAP_BASE_DIR)\Inc

##############################################################################
#  RHAPSODY required target-dependent definitions
##############################################################################
DEV_MMIO_BASE       = 0xefe00000
DEV_CLOCK_FREQ      = 180000000  # 180 MHz
DEV_APP_BASEADDRESS = 0x0840
DEV_MEM_SIZE        = 0x02000000 # 32 MByte

##############################################################################
#  CONFIGURATION BLOCK
##############################################################################
!MESSAGE Going to Build a Debug standalone application

COMPILER    = $(TMCC)
LINKER      = $(TMLD)
ARCHIVER    = $(TMAR)

PSOS_DEFS   = $(PSOS_SINGLEPROC_DEFS)
PSOS_LIBS   = $(PSOS_SINGLEPROC_LIBS)

!IFNDEF SCOS_LIBS
SCOS_LIBS   = ..\..\lib\libscpsos.a ..\..\lib\libscu.a ..\..\lib\libscc.a ..\..\lib\libtimer.a ..\..\lib\libscpsos.a
!ENDIF

HOST        = $(HOST_NONE)
TCS_CFLAGS  = -B -host $(HOST) -$(ENDIAN) -target $(TARGET) $(PSOS_DEFS)
TCS_LFLAGS  =  $(TCS_LFLAGS_EMBEDDED_APP) \
               -bcompact -bfoldcode -bremoveunusedcode

TCS_LIBS    = { $(TCS)\tmComm\$(CORE)\$(ENDIAN)\$(FP)\libio.a \
              $(TCS)\tmComm\$(CORE)\nohost\$(ENDIAN)\$(FP)\host_comm.o \
			  $(TCS)\tmComm\$(CORE)\$(ENDIAN)\$(FP)\hostcall.a \
			  $(TCS)\tmComm\$(CORE)\$(ENDIAN)\$(FP)\libIODriver.a \
              $(TCS)\libdev\lib\$(CORE)\$(TARGET)\$(ENDIAN)\$(FP)\libdev.a \
              $(TCS)\lib\$(CORE)\$(ENDIAN)\$(FP)\libc.a \
              $(TCS)\lib\$(CORE)\$(ENDIAN)\$(FP)\libC++.a \
			  $(TCS)\lib\$(CORE)\$(ENDIAN)\$(FP)\libam.a \
              $(TCS)\lib\$(CORE)\$(ENDIAN)\$(FP)\libstubs.a \
			  $(OLDLIBS)\libmon.o  }

OLD_TCS_LIBS  = { $(OLDLIBS)\libio.a \
              $(OLDLIBS)\host_comm.o \
              $(OLDLIBS)\libdev.a \
              $(OLDLIBS)\libC++.a \
              $(OLDLIBS)\libc.a \
              $(OLDLIBS)\libam.a \
              $(OLDLIBS)\libstubs.a }

RAP_LIBS    = C:\Data\IncaXetal\Bsp\Lib\TrmBspSp.a $(RAP_BASE_DIR)\Lib\RapIB311Rel.a

INTDIR  = Debug
!IFDEF MAKE_LIBRARY
OUTDIR  = ..\lib
APP     = $(OUTDIR)\$(APP_NAME).a
!ELSE
OUTDIR  = ..\bin
APP     = $(OUTDIR)\$(APP_NAME).mi
!ENDIF
FFSDIR  = ..\ffs
XTC		= $(FFSDIR)\$(APP_NAME).cmd
C_FLAGS = -w1 $(TCS_CFLAGS) -DBUILD_TRIMEDIA_BOARD -DBUILD_INCA_311_BOARD -DDEBUG
L_FLAGS = $(TCS_LFLAGS)
LIBS    =  $(SCOS_LIBS) $(RAP_LIBS) $(PSOS_LIBS) $(OLD_TCS_LIBS)

##############################################################################
# Common Create and Clean-up Targets
##############################################################################

!IFDEF XTCC_SOURCES
XTC_SOURCES = $(XTCC_SOURCES:.xtc=.asm)
!ENDIF

!IFDEF XTC_SOURCES
DEFAULT   : "$(OUTDIR)" "$(INTDIR)" "$(XTC)" "$(APP)"
!ELSE
DEFAULT   : "$(OUTDIR)" "$(INTDIR)" "$(APP)"
!ENDIF

!IFDEF XTC_SOURCES
ALL       : "$(OUTDIR)" "$(INTDIR)" CLEAN_APP CLEAN_XTC "$(XTC)" "$(APP)"
!ELSE
ALL       : "$(OUTDIR)" "$(INTDIR)" CLEAN_APP "$(APP)"
!ENDIF

CLEAN_APP : CLEAN
    @del  "$(APP)" > NUL

CLEAN_XTC : CLEAN
    @del  "$(XTC)" > NUL

CLEAN     : $(SOURCES)
    @!del "$(INTDIR)\$(**B).o" > NUL
    @del $(INTDIR)\*.xtc" > NUL
    @del $(INTDIR)\*.asm" > NUL
	
"$(OUTDIR)" :
    @if not exist "$(OUTDIR)$(NULL)" mkdir "$(OUTDIR)" > NUL

"$(INTDIR)" :
    @if not exist "$(INTDIR)$(NULL)" mkdir "$(INTDIR)" > NUL


##############################################################################
# Compile the sources and link the objects and libraries
##############################################################################
INTOBJECTS = $(SOURCES:.cpp=.o)
OBJECTS = $(INTOBJECTS:.c=.o)

bsp.a: 
	nmake /f $(PSOS_SYSTEM)\configs\Makefile.win PSOS_SYSTEM="$(PSOS_SYSTEM)" APPDIR="." AR="$(ARCHIVER)" CC="$(COMPILER)" CFLAGS="$(C_FLAGS)"

!IFDEF XTCC_SOURCES
$(XTC_SOURCES) : $(XTCC_SOURCES)
    @ECHO Compiling Xetal sources
    $(XTC_BIN)\xtcc.exe $(?F) $(?F:.xtc=.asm)
    
!ENDIF

$(XTC) : $(XTC_SOURCES)
    @ECHO Assembling Xetal sources

	$(XTC_BIN)\XetalAssemPC.exe \
		$(?F) \
		$(?F:.asm=.cmd) $(XTC_PARAMS) 6 0

	cd
	move /Y $(?F:.asm=.cmd) $(XTC)
	copy availability_inca.txt + availability.txt $(FFSDIR)\availability.txt
	
	@ECHO Finished compiling Xetal sources
	
$(APP) : $(OWN_DEPS) $(SOURCES)
!IFDEF C_SOURCES
    @ECHO Compiling C sources
    $(COMPILER) -c -Xc=mixed+inline $(C_FLAGS) $(OWN_INCLUDE) $(RAP_INCLUDE) $(TCS_INCLUDE) $(C_SOURCES)
!ENDIF
!IFDEF CPP_SOURCES
    @ECHO Compiling C++ sources
    $(COMPILER) -c -Xc=arm $(C_FLAGS) $(OWN_INCLUDE) $(RAP_INCLUDE) $(TCS_INCLUDE) $(CPP_SOURCES)
!ENDIF
	@move /Y *.o $(INTDIR) > NUL
!IFDEF OWN_DEPS
	@move /Y $(OWN_DEPS) $(INTDIR) > NUL
!ENDIF	
    @@cd $(INTDIR)
    @ECHO Linking application
!IFDEF MAKE_LIBRARY
	$(ARCHIVER) rc ..\$(APP) $(OBJECTS)
!ELSE
	$(LINKER) $(L_FLAGS) { $(OWN_DEPS) $(OBJECTS) $(OWN_LIBS) $(LIBS) } -o ..\$(APP)
!ENDIF
    @ECHO Finished compiling C sources

	

